import modules from './modules'
import Vue from 'vue'
//这里仅示范npm安装方式的引入，其它方式引入请看最上面【安装】部分
import Router from 'uni-simple-router'

Vue.use(Router)
//初始化
const router = new Router({
    routes: [...modules]//路由表
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	var token = uni.getStorageSync('token')
	if(to.path==="/pages/login/loginByUser" && from.path==="/pages/login/loginByUser"){
		next(false)
	}
	else if(to.path==="/pages/login/loginByUser"){
		next()
	}
	else{
		if(!token){
			next('/pages/login/loginByUser',)
		}
		else if(to.path === from.path){
			next(false)
		}
		else{
			next()
		}
	}
})
// 全局路由后置守卫
router.afterEach((to, from) => {
})
export default router;